package com.atom.module.mvvm.extren

import android.os.Looper
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.onStart

fun checkMainThread() {
    check(Looper.myLooper() == Looper.getMainLooper()) {
        "Expected to be called on the main thread but was " + Thread.currentThread().name
    }
}

fun <T : Any> Flow<T>.asInitialValueFlow(initialValue: () -> T): InitialValueFlow<T> =
    InitialValueFlow(
        onStart {
            emit(initialValue())
        }
    )

class InitialValueFlow<T : Any>(private val flow: Flow<T>) : Flow<T> by flow {

    fun skipInitialValue(): Flow<T> = flow.drop(1)
}

